import server.util.FileUtil;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;

public class DownLoad implements Servlet {
    @Override
    public void init(ServletConfig servletConfig) throws ServletException {

    }

    @Override
    public ServletConfig getServletConfig() {
        return null;
    }

    @Override
    public void service(ServletRequest servletRequest, ServletResponse servletResponse) throws ServletException, IOException {
        HttpServletRequest request = (HttpServletRequest) servletRequest;
        File file = new File(request.getRealPath("/index.htm"));
        System.out.println(file.getAbsolutePath());

        HttpServletResponse response = (HttpServletResponse)servletResponse;
        response.addHeader("Content-Disposition", "attachment; filename=hello.html");
//        File file = new File("E:\\WebServer\\myServer\\host\\webapps\\favicon.ico");
        FileUtil.sendData(file, response.getOutputStream());
    }

    @Override
    public String getServletInfo() {
        return null;
    }

    @Override
    public void destroy() {

    }
}
